package com.parking.mgr.common.config;

import cn.hutool.core.collection.CollectionUtil;
import com.parking.mgr.common.constant.CommonConstant;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.List;

/**
 * @ClassName SwaggerConfig
 * @Description swagger配置
 * @author: zhijianpu
 * @Date: 2025/2/28
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    private List<Parameter> getParameters() {
        Parameter parameter = new ParameterBuilder()
                .name("Authorization")
                .description("token令牌")
                .modelRef(new ModelRef("string"))
                .parameterType("header")
                .required(false)
                .build();

        Parameter clientId = new ParameterBuilder()
                .name("Client-Id")
                .description("客户端ID")
                .modelRef(new ModelRef("string"))
                .parameterType("header")
                .required(false)
                .build();


        List<Parameter> parameters = CollectionUtil.newArrayList();
        parameters.add(parameter);
        parameters.add(clientId);
        return parameters;
    }

    @Bean
    public Docket userApi() {
        List<Parameter> parameters = getParameters();
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(userApiInfo())
                .groupName("用户业务接口")
                .select()
                .apis(RequestHandlerSelectors.basePackage(CommonConstant.SYSTEM_PACKAGE_NAME))
                .paths(PathSelectors.any())
                .build()
                .globalOperationParameters(parameters);
    }

    private ApiInfo userApiInfo() {
        return new ApiInfoBuilder()
                .title("停车备案平台")
                .description("停车备案平台")
                .version("1.0")
                .build();
    }

}
